package com.kakaxi.mybilibili.module.home.find.view;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.adapter.tag.LiveCategoryRoomsTagFlowAdapter;
import com.kakaxi.mybilibili.base.BaseFragment;
import com.kakaxi.mybilibili.bean.FindHomeTagItemBean;
import com.kakaxi.mybilibili.module.home.find.presenter.FindHomePresenter;
import com.kakaxi.mybilibili.module.home.find.presenter.IFindHomePresenter;
import com.kakaxi.mybilibili.module.search.view.SearchActivity;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 发现主页面碎片类
 * Created by kakaxi on 16/10/11.
 */

public class FindHomeFragment extends BaseFragment implements IFindHomeView {

    @BindView(R.id.tflayout_find_home_small_tag)
    TagFlowLayout tagFlowLayout;

    @BindView(R.id.txt_find_home_tag_label)
    TextView textView;

    private IFindHomePresenter mPresenter;

    public static FindHomeFragment newInstance() {
        return new FindHomeFragment();
    }

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_find_home;
    }

    @Override
    protected void setupViews(ViewGroup viewGroup) {
        ButterKnife.bind(this, viewGroup);
    }

    @Override
    protected void initData() {
        mPresenter = new FindHomePresenter(this);
        mPresenter.initTagData();
    }

    @Override
    public void showTagData(List<FindHomeTagItemBean> tagItemBeanList) {
        List<String> dataList = new ArrayList<>();
        for (FindHomeTagItemBean itemBean : tagItemBeanList) {
            dataList.add(itemBean.getKeyword());
        }
        LiveCategoryRoomsTagFlowAdapter adapter = new LiveCategoryRoomsTagFlowAdapter(getContext
                (), dataList);
        tagFlowLayout.setAdapter(adapter);
        tagFlowLayout.setVisibility(View.VISIBLE);
        textView.setVisibility(View.VISIBLE);

        adapter.setOnTagClickListener(new LiveCategoryRoomsTagFlowAdapter.OnTagClickListener() {
            @Override
            public void onTagClick(View view, int position) {
                // 直接搜索点击的关键词
                Bundle bundle = new Bundle();
                bundle.putInt(SearchActivity.EXTRA_TYPE, SearchActivity.TYPE_VIDEO);
                bundle.putString(SearchActivity.EXTRA_KEYWORD, (String) view.getTag());
                goActivity(SearchActivity.class, bundle);
            }
        });
    }

    @OnClick({R.id.llayout_find_home_search,
            R.id.rlayout_find_home_new_rank_content,
            R.id.rlayout_find_home_all_rank_content,
            R.id.rlayout_find_home_topic_center,
            R.id.rlayout_find_home_activity_center,
            R.id.rlayout_find_home_group,
            R.id.rlayout_find_home_game_center})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llayout_find_home_search: { // 搜索
                Bundle bundle = new Bundle();
                bundle.putInt(SearchActivity.EXTRA_TYPE, SearchActivity.TYPE_VIDEO);
                goActivity(SearchActivity.class, bundle);
                break;
            }
            case R.id.rlayout_find_home_group: { // 兴趣圈
                toastHandler("开发中。。。");
                break;
            }
            case R.id.rlayout_find_home_topic_center: { // 话题中心
                Bundle bundle = new Bundle();
                bundle.putInt(FindCenterActivity.EXTRA_CENTER_TYPE, FindCenterActivity.TYPE_TOPIC);
                goActivity(FindCenterActivity.class, bundle);
                break;
            }
            case R.id.rlayout_find_home_activity_center: { // 活动中心
                Bundle bundle = new Bundle();
                bundle.putInt(FindCenterActivity.EXTRA_CENTER_TYPE, FindCenterActivity.TYPE_EVENT);
                goActivity(FindCenterActivity.class, bundle);
                break;
            }
            case R.id.rlayout_find_home_new_rank_content: { // 原创排行榜
                Bundle bundle = new Bundle();
                bundle.putInt(FindRankActivity.EXTRA_RANK_TYPE, FindRankActivity.TYPE_NEW);
                goActivity(FindRankActivity.class, bundle);
                break;
            }
            case R.id.rlayout_find_home_all_rank_content: { // 全区排行榜
                Bundle bundle = new Bundle();
                bundle.putInt(FindRankActivity.EXTRA_RANK_TYPE, FindRankActivity.TYPE_ALL);
                goActivity(FindRankActivity.class, bundle);
                break;
            }
            case R.id.rlayout_find_home_game_center: { // 游戏中心
                toastHandler("开发中。。。");
                break;
            }
        }
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showEmptyView() {

    }

    @Override
    public void showMessage(String message) {
        toastHandler(message);
    }
}
